package ckw.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import ckw.election.ElectionService;
import ckw.gui.MainWindow;
import ckw.manager.ManagerController;
import core.smartCardReader.SmartCardReaderService;

@Component
public class BeanProvider implements ApplicationContextAware {

	static ApplicationContext ctx;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		ctx = applicationContext;
	}

	public static ElectionService electionService() {
		return ctx.getBean(ElectionService.class);
	}

	public static ManagerController managerController() {
		return ctx.getBean(ManagerController.class);
	}

	public static SmartCardReaderService smartCardReaderService() {
		SmartCardReaderService service = ctx.getBean(SmartCardReaderService.class);
		service.setIsInDebugMode(MainWindow.isInDebugMode());
		return service;
	}
}
